package com.huluobo.a2207parkdemo.login

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.UserBean
import com.huluobo.base.db.ParkDatabase
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/11/15.
 */
@HiltViewModel
class LoginViewModel @Inject constructor(
    val apiService: ApiService,
    val db: ParkDatabase
) : BaseViewModel() {
    val loginSuccess by lazy { MutableLiveData<String>() }
    fun login(body: RequestBody) {
        executeNetwork(
            { apiService.login(body) },
            loginSuccess::postValue
        )
    }

    val insertSuccess by lazy { MutableLiveData<String>() }
    fun insertUserInfo(userBean: UserBean) {
        executeDb(
            {
                db.getUserDao().insertUserInfo(userBean)
                "添加数据库成功"
            },
            insertSuccess::postValue
        )
    }

//    val querySuccess by lazy { MutableLiveData<UserBean>() }
//    fun queryUserInfo(name: String) {
//        executeDb(
//            {
//                db.getUserDao().queryUserInfoByName(name)
//            },
//            querySuccess::postValue
//        )
//    }
}